// i.d(t, { O: () => ViewmodeData })
import viewmodeEnum from "../enum/viewmode.enum"
import Data from "../object/Data"
import ObservableValue, { createObVal } from "../observer/observable.value"
import { isPanOrMesh } from "../utils/viewmode.util"

export default class ViewmodeData extends Data {
  viewmodeChangeEnabled: boolean
  currentModeObservable: ObservableValue<number>
  transition: { active: boolean; progress: number; from: number; to: number; startTime: number; transitionTime: number }
  constructor() {
    super()
    this.name = "viewmode"
    this.viewmodeChangeEnabled = !0
    this.currentModeObservable = createObVal(null)
    this.transition = {
      active: !1,
      progress: 0,
      from: null,
      to: null,
      startTime: 0,
      transitionTime: 0
    }
    this.isPano = this.isPano.bind(this)
    this.isFloorplan = this.isFloorplan.bind(this)
    this.isInside = this.isInside.bind(this)
    this.isDollhouse = this.isDollhouse.bind(this)
    this.isOrthographic = this.isOrthographic.bind(this)
  }
  get currentMode() {
    return this.currentModeObservable.value
  }
  set currentMode(e) {
    e !== this.currentModeObservable.value && (this.currentModeObservable.value = e)
  }
  get closestMode() {
    return this.currentMode === viewmodeEnum.Transition ? (this.transition.progress < 0.5 ? this.transition.from : this.transition.to) : this.currentMode
  }
  makeModeChangeSubscription(e) {
    return this.currentModeObservable.onChanged(e)
  }
  activateTransition(from: number, to: number, transitionTime: number) {
    this.transition.active = !0
    this.transition.progress = 0
    this.transition.startTime = Date.now()
    this.transition.transitionTime = transitionTime
    this.transition.to = to
    this.transition.from = from
  }
  deactivateTransition() {
    this.transition.active = !1
  }
  isPano() {
    return this.currentMode === viewmodeEnum.Panorama
  }
  isInside() {
    return isPanOrMesh(this.currentMode)
  }
  isMesh() {
    return this.currentMode === viewmodeEnum.Mesh
  }
  isFloorplan() {
    return this.currentMode === viewmodeEnum.Floorplan
  }
  isDollhouse() {
    return this.currentMode === viewmodeEnum.Dollhouse
  }
  isOrthographic() {
    return this.currentMode === viewmodeEnum.Orthographic
  }
  canStartTransition() {
    const e = this.transition.active,
      t = this.currentMode === viewmodeEnum.Transition
    return !e && !t
  }
  transitionActive() {
    return !this.canStartTransition()
  }
  isAlreadyInMode(e: number) {
    const t = this.transition.from === this.transition.to
    const i = this.currentMode === e
    return (this.transition.active && t) || i
  }
  canSwitchViewMode(e: number) {
    return this.canStartTransition() && this.viewmodeChangeEnabled && !this.isAlreadyInMode(e)
  }
}
